<?php
    if(!isset($_REQUEST['ajax'])){include 'header.tpl.php';}
?>
                <div class="row">
                    <div class="col-lg-12">
                        <div class="gantt"></div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-5">
                        <div class="panel">
                            <div class="panel-heading">
                                <div class="panel-title"><i class="aicon-task_list"></i> <?php echo $this->language['task_update'];?></div>
                            </div>
                            <div class="panel-body">
                                <table class="table table-hover table-condensed">
                                    <thead>
                                        <tr>
                                            <th><?php echo $this->language['task_name'];?></th>
                                            <th width="100px"><?php echo $this->language['status'];?></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php foreach ($this->taskcnm as $row) { ?>
                                        <tr>
                                            <td><a href='#task_view/tid=<?php echo $row['tId'];?>' title='<?php echo $row['tTitle'];?>'><?php echo $row['tTitle'];?></a></td>
                                            <td class="text-center"><?php
                                                if($row['tStatus']==0) echo "<span class='label label-waiting'>".$this->language['waiting']."</span>";
                                                elseif($row['tStatus']==1) echo "<span class='label label-process'>".$this->language['processing']."</span>";
                                                elseif($row['tStatus']==2) echo "<span class='label label-preview'>".$this->language['testing']."</span>";
                                                elseif($row['tStatus']==3) echo "<span class='label label-complete'>".$this->language['completed']."</span>";
                                                elseif($row['tStatus']==-1) echo "<span class='label label-deny'>".$this->language['cancelled']."</span>";
                                                else echo $this->language['unknown'];
                                                ?></td>
                                        </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-7">
                        <div class="panel">
                            <div class="panel-heading">
                                <div class="panel-title"><i class="aicon-chart"></i> <?php echo $this->language['report'];?></div>
                            </div>
                            <div class="panel-body">
                                <div id="hightchart"></div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php if($_SESSION['userType']==1) {?>
                <div class="modal fade" id="ghichu">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <form action="javascript:createNote();">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title">Ghi chú mới</h4>
                                </div>
                                <div class="modal-body">
                                        <fieldset>
                                            <div class="form-group">
                                                <label for="noteTitle">Tiêu đề</label>
                                                <input type="text" class="form-control" name="noteTitle" id="noteTitle" placeholder="Tiêu đề" />
                                            </div>
                                            <div class="form-group">
                                                <label for="noteTitle">Nội dung</label>
                                                <textarea class="form-control" rows="3" name="noteComment" id="noteComment"></textarea>
                                            </div>
                                        </fieldset>
                                </div>
                                <div class="modal-footer">
                                    <input type="submit" class="btn btn-primary" value="Đồng ý" />
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <?php } ?>
                <div class="modal fade" id="task_complete" data-width='700px'>
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title">Danh sách công việc cần hoàn thành</h4>
                            </div>
                            <div class="modal-body">
                                <ul class="list-group">
                                    <?php foreach($this->reminder_tasks as $group => $tasks):
                                        if(strtotime(str_replace("/","-",$group)) < strtotime(date("m/d/Y"))) $color = 'red';
                                        elseif(strtotime(str_replace("/","-",$group)) == strtotime(date("m/d/Y"))) $color = 'green';
                                        else $color = 'blue';
                                    ?>
                                    <li class="list-group-item <?php echo $color;?>">Công việc ngày : <?php echo $group;?></li>
                                    <?php foreach($tasks as $task):?>
                                    <li class="list-group-item"><a href="#task_view/tid=<?php echo $task['tId'];?>"><?php echo $task['tTitle'];?></a></li>
                                    <?php endforeach;?>
                                    <?php endforeach;?>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>

    <script type="text/javascript" src="assets/js/jquery.gantt.min.js"></script>
    <script type="text/javascript">
        $(function() {
            $(".gantt").gantt({
                source: [
                    <?php if(count($this->tasks)>0){?>
                    <?php for($i = 0;$i < count($this->tasks);$i++){?>
                    {
                        name: "<?php echo htmlspecialchars($this->tasks[$i]['name'],ENT_QUOTES);?>",
                        desc: "<?php echo htmlspecialchars($this->tasks[$i]['desc'],ENT_QUOTES);?>",
                        values: [{
                            from: "/Date(<?php echo strtotime(date("m/d/Y",$this->tasks[$i]['start_time']))*1000;?>)/",
                            to: "/Date(<?php echo strtotime(date("m/d/Y",$this->tasks[$i]['end_time']))*1000;?>)/",
                            label: "<?php echo htmlspecialchars($this->tasks[$i]['label'],ENT_QUOTES);?>",
                            customClass: "<?php
                                if($this->tasks[$i]['status'] == 0) echo "ganttRed";
                                elseif($this->tasks[$i]['status'] == -1) echo "ganttGray";
                                elseif($this->tasks[$i]['status'] == 1) echo "ganttOrange";
                                elseif($this->tasks[$i]['status'] == 2) echo "ganttGreen";
                                elseif($this->tasks[$i]['status'] == 3) echo "ganttBlue";
                                else echo "ganttGray";
                                ?>",
                            dataObj: {id:<?php echo $this->tasks[$i]['id'];?>}
                        }]
                    }<?php echo ($i < count($this->tasks)) ? ",":"";?>
                    <?php }}else{ ?>
                    {
                        name: "",
                        values: [{
                            from: "/Date(<?php echo strtotime("-2 weeks",time())*1000;?>)/",
                            to: "/Date(<?php echo strtotime("+2 weeks",time())*1000;?>)/",
                            label: "<?php echo $this->language['calendar_empty'];?>",
                            customClass: "ganttRed"
                        }]
                    }
                    <?php } ?>
                ],
                navigate: "scroll",
                scale: "days",
                maxScale: "months",
                minScale: "days",
                itemsPerPage: 15,
                months:["Tháng 1", "Tháng 2", "Tháng 3", "Tháng 4", "Tháng 5", "Tháng 6", "Tháng 7", "Tháng 8", "Tháng 9", "Tháng 10", "Tháng 11", "Tháng 12"],
                waitText:"Loading....",
                onItemClick: function(data) {
                    window.location.hash = 'task_view/tid='+data.id;
                }
            });

            <?php if(count($this->reminder_tasks) > 0):?>
            setTimeout(function(){
                $("#task_complete").modal('show');
            },2000);
            <?php endif;?>
        });
    </script>
<?php if(isset($this->breadcrumb) && isset($this->title_header)):?>
    <script type="text/javascript">
        $(function() {
            $("#title-header").text('<?php echo $this->title_header;?>');
            $("#breadcrumb").html('<?php echo build_breadcrumb($this->breadcrumb);?>');
        });
    </script>
<?php endif;?>
<?php
    if(!isset($_REQUEST['ajax'])){include 'footer.tpl.php';}
?>